<template>
  <div>
    <van-nav-bar
      title="地址"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <van-address-edit
      :area-list="areaList"
      show-postal
      :addressInfo="addressInfo"
      show-delete
      show-set-default
      show-search-result
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      @save="onSave"
      @delete="onDelete"
    />
  </div>
</template>

<script>
import $axios from "@/api/request";
export default {
  data() {
    return {
      addressInfo: {},
      areaList: {
        province_list: {
          110000: "北京市",
          120000: "湖南省",
        },
        city_list: {
          110100: "北京市",
          120100: "长沙市",
        },
        county_list: {
          110101: "东城区",
          110102: "天心区",
        },
      },
    };
  },
  created() {
    this.Datail();
  },
  methods: {
    onClickLeft() {
      this.$router.back();
    },

    onSave(item) {
      let {
        addressDetail,
        addressId,
        areaCode,
        city,
        country,
        county,
        createTime,
        isDefault,
        name,
        postalCode,
        province,
        tel,
        updateTime,
        userId,
      } = item;
      let params = {
        addressId: this.$route.query.addressId,
        addressDetail,
        addressId,
        areaCode,
        city,
        country,
        county,
        createTime,
        isDefault,
        name,
        postalCode,
        province,
        tel,
        updateTime,
        userId,
      };
      $axios
        .post("http://zl.huruqing.cn:3003/address/edit", params)
        .then((res) => {});
      this.$router.push({
        path: "/adress",
        query: {preOrderId: this.$route.query.preOrderId,total: this.$route.query.total },
      });
    },
    onDelete() {
      $axios
        .post(
          "http://zl.huruqing.cn:3003/address/del?addressId=" +
            this.$route.query.addressId
        )
        .then((res) => {
          console.log(res);
        });
    },
    Datail() {
      $axios
        .post(
          "http://zl.huruqing.cn:3003/address/detail?addressId=" +
            this.$route.query.addressId
        )
        .then((res) => {
          this.addressInfo = res.result;
        });
    },
  },
};
</script>

<style>
</style>